<?php
use think\migration\Migrator;
use think\migration\db\Column;

class CreateProductAnyshootTasks extends Migrator
{
    public function change()
    {
        $this->table('product_anyshoot_tasks', ['engine' => 'InnoDB'])
            ->addColumn('user_id', 'integer', ['comment' => '用户ID'])
            ->addColumn('task_id', 'string', ['limit' => 64, 'comment' => '远程任务ID'])
            ->addColumn('template_id', 'string', ['limit' => 64, 'comment' => '模板ID'])
            ->addColumn('product_image_file_id', 'string', ['limit' => 64, 'comment' => '商品图片文件ID'])
            ->addColumn('product_mask_file_id', 'string', ['limit' => 64, 'null' => true, 'comment' => '商品遮罩文件ID'])
            ->addColumn('template_image_file_id', 'string', ['limit' => 64, 'null' => true, 'comment' => '模板图片文件ID'])
            ->addColumn('template_mask_file_id', 'string', ['limit' => 64, 'null' => true, 'comment' => '模板遮罩文件ID'])
            ->addColumn('mode', 'string', ['limit' => 20, 'default' => 'advanced', 'comment' => '生成模式'])
            ->addColumn('generating_count', 'integer', ['default' => 1, 'comment' => '生成数量'])
            ->addColumn('status', 'integer', ['limit' => 1, 'default' => 0, 'comment' => '状态：0待处理,1图片生成中,2图片生成失败,3图转视频中,4图转视频失败,5图转视频成功'])
            ->addColumn('result_images', 'text', ['null' => true, 'comment' => '结果图片列表JSON'])
            ->addColumn('video_task_id', 'string', ['limit' => 64, 'null' => true, 'comment' => '图转视频任务ID'])
            ->addColumn('result_videos', 'text', ['null' => true, 'comment' => '结果视频列表JSON'])
            ->addColumn('error_msg', 'string', ['limit' => 255, 'null' => true, 'comment' => '错误信息'])
            ->addColumn('points_consumed', 'integer', ['default' => 0, 'comment' => '消耗积分'])
            ->addColumn('create_time', 'timestamp', ['default' => 'CURRENT_TIMESTAMP', 'comment' => '创建时间'])
            ->addColumn('update_time', 'timestamp', ['null' => true, 'comment' => '更新时间'])
            ->addColumn('image_complete_time', 'timestamp', ['null' => true, 'comment' => '图片生成完成时间'])
            ->addColumn('video_complete_time', 'timestamp', ['null' => true, 'comment' => '视频生成完成时间'])
            ->addIndex(['task_id'], ['unique' => true])
            ->addIndex(['user_id'])
            ->addIndex(['status'])
            ->addIndex(['create_time'])
            ->create();
    }
} 